<?php
/**
 * Func   信用彩种开奖类别
 */
defined('IN_YuLin') || exit('NO PERMIT!');

$table = Table('lottery_credit_type');
$page  = '';
$operation = NoBadStr($_REQUEST['operation']);
switch ($operation){
    case 'add':
        $id   = NoBadStr($_REQUEST['id']);
        if ($id){
            $sql  = 'SELECT id, title, status FROM ' . $table . ' WHERE id = ' . $id;
            $info = $db->getrow($sql);
        }
        $page = 'lottery/credit_typelist_add';
        // 预留
        break;
    case 'doadd':
        $ins = array(
            'title'  => NoBadStr($_POST['title']),
            'status' => NoBadStr($_POST['status']),
        );
        $id  = NoBadStr($_POST['id']);
        if($id) {
            $sql = 'UPDATE ' . $table . ' SET ' . CreateUpdateSql($ins) . ' WHERE id = ' . $id;
        }else{
            $sql = 'INSERT INTO ' . $table . ' SET ' . CreateUpdateSql($ins);
        }
        $flag = $db->exec($sql);
        if ($flag){
            ShowMsg('操作成功', U('lottery/credit_typelist'));
        }else{
            ShowMsg('操作失败', -1);
        }
        break;
    default:
        $sql  = 'SELECT id, title FROM ' . $table . ' WHERE status = 0';
        $list = $db->getall($sql);
        $sql  = 'SELECT play.id as play_id, play.lott_id, play.type_id, play.open_param, play.status,
                tp.id as type_id, tp.title
                FROM ' . Table('lottery_credit_play') . ' AS play
                LEFT JOIN ' . Table('lottery_credit_type') . ' AS tp 
                ON play.`type_id` = tp.`id`';
        $playSetList = $db->getall($sql);
        $lottIdKey   = array();
        foreach ($playSetList as $k => $v){
            $lottIdKey[$v['lott_id']][] = $v;
        }
        $page = 'lottery/credit_typelist';
        break;
}
$tpl->display($page);

